
// worker.js
const { isMainThread, parentPort } = require('worker_threads');
let registerCter = require("../controller/register.cter");

if (isMainThread) {
    throw new Error('Its not a worker');
}
// 子线程执行
const taskFun = (data) => {
    return new Promise(async (resolve, reject) => {
        try {
            console.log(`子线程接收到->${data}`);
            let info = await registerCter.register(data);
            
            resolve(info);
        } catch (error) {
            console.error(error)
            reject(error)
        }
    })
};
//2.子线程接收传过来的数据，并进行cpu耗时操作
parentPort.on('message', async (data) => {
    const result = await taskFun(data);
    parentPort.postMessage(result);
});